//
//  StreetscapeViewController.m
//  仿微信扫街景
//
//  Created by 李志伟 on 15/8/24.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "StreetscapeViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "AppDelegate.h"

#import "BaiduPanoramaView.h"

//#import "BaiduPanoUtils.h"

@interface StreetscapeViewController ()<BMKLocationServiceDelegate>

@property(strong, nonatomic) BaiduPanoramaView  *panoramaView;

@property (nonatomic,strong) AppDelegate *myDelegate;



@end

@implementation StreetscapeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationItem.title = @"扫街景";
    
    
    self.myDelegate = [UIApplication sharedApplication].delegate;
    CLLocationDegrees latitude = self.myDelegate.coordinate.latitude;
    CLLocationDegrees longitude = self.myDelegate.coordinate.longitude;
    
    NSLog(@"%f   %f",latitude,longitude);
    
    [self customPanoViewWithLon:longitude Lat:latitude];
    
    
    
    
}


- (void)customPanoViewWithLon:(double)lon Lat:(double)lat{
    CGRect frame = self.view.bounds;
    
    // key 为在百度LBS平台上统一申请的接入密钥ak 字符串
    self.panoramaView = [[BaiduPanoramaView alloc] initWithFrame:frame key:@"Mtz7OWHaHtrQGWjn5bGYBUyn"];
    
    [self.panoramaView setPanoramaWithLon:lon lat:lat];
    
    // 为全景设定一个代理
//    self.panoramaView.delegate = self;
    
    [self.view addSubview:self.panoramaView];
    
    // 设定全景的清晰度， 默认为middle
    [self.panoramaView setPanoramaImageLevel:ImageDefinitionMiddle];
    // 设定全景的pid， 这是指定显示某地的全景，也可以通过百度坐标进行显示全景
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, self.view.bounds.size.width, 50)];
    label.textColor = [UIColor whiteColor];
    [self.panoramaView addSubview:label];
    
    CLGeocoder *geo = [[CLGeocoder alloc] init];
    
    CLLocation *local = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
    
    [geo reverseGeocodeLocation:local completionHandler:^(NSArray *placemarks, NSError *error) {
        
        if(placemarks.count == 0 || error)return;
        
        CLPlacemark *clp = [placemarks firstObject];
        
        
        label.text = clp.name;
        NSLog(@"%@",clp.name);
        
    }];
    
    
}





@end
